/***********************判断是否是数字********************/
function isNumber(numberValue){
	var re =/(^[0-9][0-9]*$)|(^[0-9][0-9]*.[0-9]+$)/;
	if(typeof(numberValue)!='undefined' && re.test(numberValue)){
		return true;
	}else{
	   return false;
   }
}

function isFloat(numberValue) { 
	if (/^(\+|-)?\d+($|\.\d+$)/.test(numberValue )) { 
		return true; 
	} else { 
		return false; 
	} 
} 
/****************判断是不是中文**************************/
function isChinese(obj){
	if((/[\u4e00-\u9fa5]+/).test(obj)){      
		return true;
	}else{
		return false;
	}
}

/****************判断是不是正整数**************************/
function isSignlessIntegral(numberValue){
	var r=/^[0-9]*[1-9][0-9]*$/;
	if(typeof(numberValue)=='underfined' || !r.test(numberValue) || parseInt(numberValue)<0){
		return false;
	}
	else{
		return true;
	}
}
/***************判断是否只有字母或数字及其组合***********************/
function isStrNumber(str){
	var re=/^[a-zA-Z0-9]*$/;
	if(str.match(re)){
	   	return true;			
	 }
	else{
	    //alert("请输入字母、数字、及其组合");
		return false;
	}
}
 
/*****************判断字符串的长度 一个汉字两个字符处理*************************************/
function strLength(str){	
	return str.replace(/[^\x00-\xff]/g,'##').length;
}	
/***********************判断是否是字母********************/
function isLetter(letterid){
var re = new RegExp(/[a-zA-Z]+/i);
var kk=document.getElementById(letterid).value;
if(re.test(kk)){
return true;}else{
return false;}}
/*************验证邮件地址***************/
function checkMailUtil(str){
	var mail=/^(.+)@(.+)\.(.+)$/;
	if(!mail.test(str))
		return false;
	var illegalChar = /^(.*)['"‘“\/\\<>](.*)$/;
	if (illegalChar.test(str))
		return false;
	else
		return true;
}
/*********判断电话格式,手机***********/
function isMobilePhone(idnumber){
	try{
			var objRegExp=/^(?:13\d|15[0123689]|18[0689])-?\d{5}(\d{3}|\*{3})$/; //手机
			var mobileText =idnumber.replace(/(^\s*)|(\s*$)/g, "");
			if(mobileText.length == 0){				
				return false;
			}
			if(objRegExp.test(mobileText)){			
				return true;
			}
			else{
				return false;	
			}
		}catch(exception){
			alert(exception.message);
			return false;
		}
}
/*********判断电话格式***********/
function isPhone(idnumber){
var re = new RegExp(/[0-9]{3,4}[-]{1,1}[0-9]{7,8}/i);
var kk;
//--Modify by yanyong-
if(document.getElementById(idnumber)==null)
{
	kk=idnumber;
}
else
{
	kk=document.getElementById(idnumber).value;
}
if(re.test(kk)){
return true;
}else{
return false;
}}
/*********判断联系方式**********/
function isLink(idnumber)
{	
	var mobile = new RegExp(/1[3|5]{1,1}[0-9]{1,1}[0-9]{8,8}/i);
	var phone= new RegExp(/[0-9]{3,4}[-]{1,1}[0-9]{7,8}/i);
    var kk=document.getElementById(idnumber).value;
    var obj=document.getElementById(idnumber);
    if(phone.test(kk))
    {
    	return true;	
    }
    else if(mobile.test(kk) && kk.length==11)
    {
    	return true;
    }
    else
    {
    	alert("请输入正确的联系方式\r\n\r\n如为座机其分机用逗号隔开,格式如下：\r\n\r\n 020-88888888,888");
    	obj.focus();
    	return false;
    }
}
/***********判断身份证号********************/
function CheckCard(idCard){
	var id=idCard;
    var id_length=id.length;

    if (id_length==0){
        alert("请输入身份证号码!");
        return false;
    }

    if (id_length!=15 && id_length!=18){
        alert("身份证号长度应为15位或18位！");
        return false;
    }

    if (id_length==15){
        yyyy="19"+id.substring(6,8);
        mm=id.substring(8,10);
        dd=id.substring(10,12);

        if (mm>12 || mm<=0){
            alert("输入身份证号,月份非法！");
            return false;
        }

        if (dd>31 || dd<=0){
            alert("输入身份证号,日期非法！");
            return false;
        }

        birthday=yyyy+ "-" +mm+ "-" +dd;

        if ("13579".indexOf(id.substring(14,15))!=-1){
            sex="1";
        }else{
            sex="2";
        }
    }else if (id_length==18){
        if (id.indexOf("X") > 0 && id.indexOf("X")!=17 || id.indexOf("x")>0 && id.indexOf("x")!=17){
            alert("身份证中\"X\"输入位置不正确！");
            return false;
        }

        yyyy=id.substring(6,10);
        if (yyyy>2200 || yyyy<1900){
            alert("输入身份证号,年度非法！");
            return false;
        }

        mm=id.substring(10,12);
        if (mm>12 || mm<=0){
            alert("输入身份证号,月份非法！");
            return false;
        }

        dd=id.substring(12,14);
        if (dd>31 || dd<=0){
            alert("输入身份证号,日期非法！");
            return false;
        }

        if (id.charAt(17)=="x" || id.charAt(17)=="X")
        {
            if ("x"!=GetVerifyBit(id) && "X"!=GetVerifyBit(id)){
                alert("身份证校验错误，请检查最后一位！");
                return false;
            }

        }else{
            if (id.charAt(17)!=GetVerifyBit(id)){
                alert("身份证校验错误，请检查最后一位！");
                return false;
            }
        }

        birthday=id.substring(6,10) + "-" + id.substring(10,12) + "-" + id.substring(12,14);
        if ("13579".indexOf(id.substring(16,17)) > -1){
            sex="1";
        }else{
            sex="2";
        }
    }

    return true;
}

function GetVerifyBit(id){
        var result;
        var nNum=eval(id.charAt(0)*7+id.charAt(1)*9+id.charAt(2)*10+id.charAt(3)*5+id.charAt(4)*8+id.charAt(5)*4+id.charAt(6)*2+id.charAt(7)*1+id.charAt(8)*6+id.charAt(9)*3+id.charAt(10)*7+id.charAt(11)*9+id.charAt(12)*10+id.charAt(13)*5+id.charAt(14)*8+id.charAt(15)*4+id.charAt(16)*2);
        nNum=nNum%11;
        switch (nNum){
           case 0 :
              result="1";
              break;
           case 1 :
              result="0";
              break;
           case 2 :
              result="X";
              break;
           case 3 :
              result="9";
              break;
           case 4 :
              result="8";
              break;
           case 5 :
              result="7";
              break;
           case 6 :
              result="6";
              break;
           case 7 :
              result="5";
              break;
           case 8 :
              result="4";
              break;
           case 9 :
              result="3";
              break;
           case 10 :
              result="2";
              break;
        }
        //document.write(result);
        return result;
}
/*********判断日期格式***********/
function isDate(idnumber){
var re = new RegExp(/[0-9]{4}-[1-9]{0,1}[0-9]{1}-[1-9]{0,1}[0-9]{1}/i);
//var kk=document.getElementById(idnumber).value;
if(re.test(idnumber)){
	return true;
}else{
	return false;
	}
}

/***四舍五入**/
Number.prototype.toFixed=function(n){
  with(Math)   return   round(Number(this)*pow(10,n))/pow(10,n)
}

function addpoint(str,position){
	var tempStr="";
	for(var i=0;i<str.length;i++){
		if(i==position){
			tempStr+='.';
		}
		tempStr+=str.substr(i,1);
	}
	return tempStr;
}
/***判断是否数字**/
String.prototype.isNumber=function(){
var re = new RegExp(/^\d+(\.\d+)?$/);
if(re.test(this+"")){
return true;
}else{
return false;
}
}
function setCookie(cookiename,cookievalue) {
	delCookie(cookiename);
	var expireDate = new Date();
	expireDate.setMonth(expireDate.getMonth()+6);
	document.cookie = cookiename+"=" + encodeURI(cookievalue) + ";expires=" + expireDate.toGMTString();
}

function cookieVal(cookieName) {
	var thisCookie = document.cookie. split("; ");
	for (var i=0; i<thisCookie. length; i++) {
		if (cookieName == thisCookie[i].split("=")[0]) {
			return decodeURI(thisCookie[i]. split("=")[1]);
		}
	}
	return "";
}
function delCookie(Key) {
	var today=new Date();
	document.cookie = Key + "=null;expires="+today.toGMTString;
}

/***格式化日期**/
function formatDate(datevalue,formatvalue){
var nowyear=datevalue.getUTCFullYear();
var nowmonth=datevalue.getUTCMonth();
var nowday=datevalue.getUTCDate();
if("YYYYMMDD"==formatvalue){
return nowyear+""+nowmonth+""+nowday;
}else if("YYYY-MM-DD"==formatvalue){
return nowyear+"-"+nowmonth+"-"+nowday;
}else if("YYYY/MM/DD"==formatvalue){
return nowyear+"/"+nowmonth+"/"+nowday;
}}
/***对两个日期进行对比**/
function compareToDate(datevalue1,datevalue2){
var nowyear1=datevalue1.getUTCFullYear();
var nowmonth1=datevalue1.getUTCMonth();
var nowday1=datevalue1.getUTCDate();
var nowyear2=datevalue2.getUTCFullYear();
var nowmonth2=datevalue2.getUTCMonth();
var nowday2=datevalue2.getUTCDate();
if(nowyear1>nowyear2){
return 1;
}else if(nowyear1<nowyear2){
return -1;
}else if(nowyear1==nowyear2){
if(nowmonth1>nowmonth2){
return 1;
}else if(nowmonth1<nowmonth2){
return -1;
}else if(nowmonth1==nowmonth2){
if(nowday1>nowday2){
return 1;
}else if(nowday1<nowday2){
return -1;
}else{return 0;
}}}}
function trim(str){
	return str.replace(/(^\s*)|(\s*$)/g,"");
}
/******将字符串转换成日期类型*********/
function toDate(str){
	var arys= new Array();
  arys=str.split('-');
  var newDate=new Date(arys[0],arys[1],arys[2]); 
  return newDate;
}
/***动态加载css样式***/
function loadCss(file){
    var cssTag = document.getElementById('loadCss');
    var head = document.getElementsByTagName('head').item(0);
    if(cssTag) head.removeChild(cssTag);
    css = document.createElement('link');
    css.href = file;
    css.rel = 'stylesheet';
    css.type = 'text/css';
    css.id = 'loadCss';
    head.appendChild(css);
}
/********动态加载js********/
function setJs(_path){
	var jstext="";
	new Ajax.Request(_path, {method: 'get',asynchronous:false,onSuccess: function(transport) {
		jstext=transport.responseText;
		if(window.execScript){
        window.execScript(jstext);//ie
      }else{
        window.eval(jstext); //firefox
   	}
  }});
  return jstext;
}


//检查是否是字母
function isLetterName(numberValue){
	var re = /(^[a-zA-Z]$)/;
	if(typeof(numberValue)!='underfined' && re.test(numberValue)){
		return true;
	}else{
	   return false;
    }
}
//检查是否是数字或字母
function isNumberOrLetterName(numberValue){
	var re = /(^[a-zA-Z]{1}$)|(^[0-9]{1,}$)/;
	if(typeof(numberValue)!='underfined' && re.test(numberValue)){
		return true;
	}else{
	   return false;
    }
}